package ten;

public class 十九线程联合 {
    public static void main(String[] args) {
        new Thread(new FatherThread()).start();
    }
}


class FatherThread implements Runnable{
    @Override
    public void run() {
        System.out.println("father want to smoke");
        System.out.println("ask son for buying smoke");
        Thread son = new Thread(new SonThread());
        son.start();
        try {
            son.join();
        } catch (InterruptedException e) {
            System.out.println("son was hurt by a car");
            e.printStackTrace();
        }
        System.out.println("father is smoking so happy");
    }
}

class SonThread implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("son buy smoke: " + i);
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("son give smoke to your father");
    }
}